You may fail to log in Ubuntu due to the following reasons:
/etc/environment or /etc/profile is modified to a wrong format: Just modify them back.
startX is used improperly: run
sudo rm -r .Xauthority*
Tips: use Ctr+Alt+F1~6 corresponding to tty 1~6 to use command line